<template>
	<view class="tabbar-container">
		<block v-for="item in list" :key="item.activePage">
			<view class="tabbar-item" @click="onSwitchTab(item)">
				<image class="tabbar-item-icon" mode="heightFix"
					:src="currentSelect === item.activePage ? item.selectedIconPath : item.iconPath"></image>
				<view class="tabbar-item-text">{{ item.text }}</view>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		name: 'Tabbar',
		props: ['currentSelect'],
		data() {
			return {
				list: [],
				allList: [{
						'pagePath': '/pages/home/index',
						'text': '比分',
						'iconPath': '/static/tabbar/score.png',
						'selectedIconPath': '/static/tabbar/score-active.png',
						'activePage': 'home'
					}, {
						'pagePath': '/pages/collectPage/index',
						'text': '大V集合',
						'iconPath': '/static/tabbar/collect.png',
						'selectedIconPath': '/static/tabbar/collect-active.png',
						'activePage': 'collectPage'
					}, {
						'pagePath': '/pages/specialColumnPage/index',
						'text': '大V专栏',
						'iconPath': '/static/tabbar/special-column.png',
						'selectedIconPath': '/static/tabbar/special-column-active.png',
						'activePage': 'specialColumnPage'
					}, {
						'pagePath': '/pages/userPage/index',
						'text': '我的',
						'iconPath': '/static/tabbar/my.png',
						'selectedIconPath': '/static/tabbar/my-active.png',
						'activePage': 'myPage'
					}
				]
			};
		},
		created() {
			console.log('组件：全局tabbar')
		},
		mounted() {
			this.list = this.allList.map((item) => item)
		},
		methods: {
			onSwitchTab(item) {
				console.log(item.pagePath)
				const url = item.pagePath
				uni.switchTab({
					url: url
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.tabbar-container {
		position: fixed;
		bottom: 0;
		display: flex;
		justify-content: space-around;
		padding: 12rpx 0 18rpx;
		width: 100%;
		// border-radius: 24rpx 24rpx 0 0;
		// box-shadow: 0px -4rpx 30rpx 0px rgba(0, 0, 0, 0.1);
		background: #fff;
		z-index: 999;

		.tabbar-item {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			width: 100rpx;

			.tabbar-item-icon {
				width: 48rpx;
				height: 48rpx;
			}

			.tabbar-item-text {
				font-size: 22rpx;
				color: #9094A6;
			}
		}
	}
</style>